'''
Created on 02/11/2012

@author: GabrielBacelar
'''

class ValueIteration():
    '''
    classdocs
    '''

    def __init__(self):
        '''
        Constructor
        '''
        self.rewardruns = 0
        self.policyruns = 0
        self.actionruns = 0
        
        self.actions = []
        self.nodes = []
        self.gama = 0.0
        self.T = {}
        self.R = {}
        self.V = {}
        
    def getValueIteration(self, node):
        return max(self.getActionValue(node))
    
    def getActionValue(self, node):
        actionValues=[]
        for action in self.actions:
            actionValues.append((self.getRewardValue(action,node),action))
        return actionValues
    
    def getRewardValue(self,action,node):
        rewards = []
        for nodePrime in self.nodes:
            if (node,action,nodePrime) in self.T:
                transition = self.T[(node,action,nodePrime)]
                reward = self.R[(node,action,nodePrime)]
                value = self.V[nodePrime]
                rewards.append(transition * (reward + (self.gama * value)))
        return sum(rewards)